package logic

import (
	"context"
	"errors"
	"video-guard/models/mysql"

	"video-guard/videorpc/internal/svc"
	"video-guard/videorpc/videorpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ReplyAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewReplyAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ReplyAddLogic {
	return &ReplyAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ReplyAddLogic) ReplyAdd(in *videorpc.ReplyAddRequest) (*videorpc.ReplyAddResponse, error) {
	// todo: add your logic here and delete this line

	comment := mysql.CommentInfo{
		VideoId:        int(in.VideoId),
		UserId:         int(in.UserId),
		CommentContent: in.CommentContent,
		IsAnonymous:    int(in.IsAnonymous),
		ReplyId:        int(in.ReplyId),
	}

	err := comment.CommentAdd(mysql.DB)
	if err != nil {
		return nil, errors.New("添加失败")
	}

	return &videorpc.ReplyAddResponse{
		CommentId: int64(comment.ID),
	}, nil
}
